/*
 * Created on Aug 14, 2008
 * (c) 2009 by Reach Unlimited Corporation
 */
package com.mgmaps.maps;

import java.util.Vector;
import com.mgmaps.app.APPSettings;
import com.nutiteq.maps.GeoMap;
import com.nutiteq.maps.UnstreamedMap;
import com.nutiteq.maps.projections.EPSG3785;
import com.nutiteq.ui.StringCopyright;

public class GoogleMap extends EPSG3785 implements GeoMap, UnstreamedMap {

  // private int mt;
  private GoogleLayers bgLayer;

  public GoogleMap(int mt) {
    super(new StringCopyright("Map data © Google"), 256, 0, 19);
    // TODO zoom max should be set to 22 for satellite
    // this.mt = mt;
    Vector layersVector = new Vector();
    if ((mt & GoogleLayers.MT_BG) == GoogleLayers.MT_SATELLITE) {
      layersVector.addElement(GoogleLayers.LAYER_SATELLITE);
      mt &= ~GoogleLayers.MT_BG;
    }
    final int mtmm = mt & GoogleLayers.MT_MAPMAKER;
    if (mtmm != 0) {
      layersVector.addElement(new GoogleLayers(mtmm));
      mt &= ~GoogleLayers.MT_MAPMAKER;
    }
    final int mtmmm = mt & GoogleLayers.MT_MAPMAKER_MOD;
    if (mtmmm != 0) {
      layersVector.addElement(new GoogleLayers(mtmmm));
      mt &= ~GoogleLayers.MT_MAPMAKER_MOD;
    }
    if (mt != 0)
      layersVector.addElement(new GoogleLayers(mt));
    bgLayer = (GoogleLayers) layersVector.elementAt(0);
    int sz = layersVector.size();
    for (int i=1; i<sz; i++)
      addTileOverlay((GoogleLayers) layersVector.elementAt(i));
    setMissingTileImage(APPSettings.missingTileImage);
  }

  public String buildPath(final int x, final int y, final int zoom) {
    final int tmpX = x >> 8;
    final int tmpY = y >> 8;
    return bgLayer.buildPath(tmpX, tmpY, zoom);
  }
}
